package com.orphan.audit.controller;


import com.orphan.audit.po.OrderCheck;
import com.orphan.audit.service.IOrderCheckService;
import com.orphan.util.dto.OrderDto;
import com.orphan.util.dto.OrderGoodsDto;
import com.orphan.util.dto.SettlementSupplierDto;
import io.swagger.annotations.Api;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wdn
 * @since 2021-07-15
 */
@RestController
@RequestMapping("/order-check")
@Api("购物结算审核")
public class OrderCheckController {

    @Autowired
    IOrderCheckService orderCheckService;
    @Autowired
    RabbitTemplate rabbitTemplate;


    @RequestMapping("/getOrder")
//    @RabbitListener(queues = "settlementQueue")
    public List<OrderCheck> getOrder() {
        List<OrderCheck> orderList = orderCheckService.findAll();
        System.out.println(orderList);
        return orderList;
    }

    @GetMapping("/getAll")
    public Object findByItem(Integer pageNO){
        return orderCheckService.getAll(pageNO);
    }

    @GetMapping("/test")
    public String test(){
        OrderGoodsDto goodsDto = new OrderGoodsDto();
        List<OrderGoodsDto> goodsList = new ArrayList<>();
        String id = UUID.randomUUID().toString();
        goodsDto.setOrderId(id);
        goodsDto.setGoodsName("旺旺雪饼");
        goodsDto.setGoodsType("小吃");
        goodsDto.setGoodsPrice(400F);
        goodsDto.setGoodsCount(20);
        goodsDto.setGoodsOrderStatus(0);
        goodsDto.setGoodsPicture("图片地址");
        goodsList.add(goodsDto);

        OrderDto orderDto = new OrderDto();
        orderDto.setOrderId(id);
        orderDto.setUserId(1);
        orderDto.setGoodsList(goodsList);
        orderDto.setTotalAmount(8000F);
        orderDto.setConsignee("张三");
        orderDto.setConsigneeTel("11111111111");
        orderDto.setOrderAddress("测试地址");
        orderDto.setOrderTime(new Date());
        orderDto.setPayMethod(1);
        orderDto.setOrderStatus(0);
        orderDto.setPayStatus(1);
        String str = "sb";
        rabbitTemplate.convertAndSend("SettlementBackDirectExchange","settlementBackMessage",orderDto);

        return "发了";
    }
}

